package com.dji.sdk.self.internal.utils;

import android.app.ActivityManager;
import android.content.Context;
import android.text.TextUtils;
import android.util.Log;

import java.util.ArrayList;

public class ServiceUtils {
    public static boolean isServiceWorking(Context context, String serviceName){
        if(TextUtils.isEmpty(serviceName)){
            return false;
        }
        ActivityManager manager = (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE);
        ArrayList<ActivityManager.RunningServiceInfo> runningServiceInfos = (ArrayList<ActivityManager.RunningServiceInfo>) manager.getRunningServices(1000);
        for (int i=0;i<runningServiceInfos.size();i++){
            Log.i("服务运行：",""+runningServiceInfos.get(i).service.getClassName().toString());
            if (runningServiceInfos.get(i).service.getClassName().toString().equals(serviceName)) {
                return true;
            }
        }
        return false;
    }
}
